package com.vimi8.ebb.auth.service;

import com.vimi8.ebb.auth.model.DBUserDetails;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by xuybin on 2016/9/9.
 */
@Mapper
public interface DBUserDetailsService {
    @Select("select phone_number as username,password as password,auth_code as authCode,!auth_code_is_used as credentialsNonExpired,TRUE as accountNonExpired,TRUE as accountNonLocked,is_enabled as enabled " +
            "from oauth_user where phone_number=#{phoneNumber} AND phone_number IS NOT NULL")
    public DBUserDetails getUserDetailsByPhoneNumber(String phoneNumber);

    @Select("select id_card as username,password as password,TRUE as credentialsNonExpired,TRUE as accountNonExpired,TRUE as accountNonLocked,is_enabled as enabled " +
            "from oauth_user where id_card=#{idCard} AND id_card IS NOT NULL")
    public DBUserDetails getUserDetailsByIdCard(String idCard);

    @Select("select user_name as username,password as password,TRUE as credentialsNonExpired,TRUE as accountNonExpired,TRUE as accountNonLocked,is_enabled as enabled " +
            "from oauth_user where user_name=#{username} AND user_name IS NOT NULL")
    public DBUserDetails getUserDetailsByUsername(String username);

    @Update("update oauth_user set auth_code_is_used=1 where phone_number=#{phoneNumber} ")
    public int updateUserDetailsForAuthCodeIsUsed(String phoneNumber);

    @Select("select client_id from oauth_client_user where open_id = #{openId}")
    public List<String> getAllClientIdByOpenId(@Param("openId") String openId);
}
